<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>全返</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../script/jquery.validation.min.js"></script>
<{if $smarty.get.operation=='add' or $smarty.get.operation=='edit' or $smarty.get.operation=='batch' }>
<script language="javascript" src="../script/Calendar.js"></script>
<{else}>
<link href="cxcalendar.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="../script/Calendar-new.js"></script>
<{/if}>
<script src="../script/my_lightbox.js" language="javascript"></script>
<script language="javascript">
var weburl="<{$config.weburl}>";
$(function(){
	
	//时间搜索
	$('.input_cxcalendar').each(function(){
	    var a = new Calendar({
	        targetCls: $(this),
	        type: 'yyyy-mm-dd HH:MM:SS',
	        wday:2
	    },function(val){
	        console.log(val);
	    });
	});
	
	$('#form').validate({
		errorPlacement: function(error, element){
			element.next('.form-error').append(error);
		},      
		rules : {
			hp_title:{
				required:true
			},
			pic:{
				required:true
			},
			pid:{
				required:true
			},
			limit_amount:{
				required:true
			},
			low_amount:{
				required:true
			}
		},
		messages : {
			hp_title:{
				required:'请填写全返名称',
			},
			pic:{
				required:'请上传图片',
			},
			pid:{
				required:'请选择商品',
			},
			limit_amount:{
				required:'请填写',
			},
			low_amount:{
				required:'请填写',
			},
		}
	});
	
	$('#pid').bind('click change',function(){
	var $$=$(this);
	//alert($$.val());

	if(!$$.val()){return false;}


	if(/[^\d]/.test($$.val())){

		alert('请输出正确的产品id');
		$(this).val('');
		return false;

	}

	$.getJSON('?m=huopin&s=huopin.php&operation=getsku&pid='+$$.val()+'&hp_id='+$('#id').val(),function(data){
		if (!data) {alert('未找到此商品，请确认商品已上架');return false;}
			var str='<table width="100%" class="alc"><tbody><tr><th width="100" align="left">产品图</th><th width="350">产品名称</th><th width="200" align="left">规格</th><th>产品价格</th><th>分销价</th><th>全返价格</th><th>建议零售价</th><th width="100">全返库存</th><th width="100">已售</th><th width="100">是否全返此sku</th></tr>';
				$.each(data,function(k,v){
					str+='<tr><td><img width="50" src="'+v.pic+'"></td>';
					str+='<td class="al"><input type="hidden" name="skuid[]" value="'+v.id+'"><input type="hidden" name="stock_shop[]" value="'+v.stock_shop+'"><div class="name">'+v.pname+'</div></td>';
				  str+='<td><div class="name">'+v.spec+'</div></td>';
				  str+='<td>'+v.price+'</td>';
				   str+='<td>'+v.dis_price+'</td>';
				  str+='<td><input type="text" style="width:80px;" name="hp_price[]" value="'+v.hp_price+'"></td>';
				 str+='<td><input type="text" style="width:80px;" name="hp_market_price[]" value="'+v.hp_market_price+'"></td>';
				  str+='<td align="center"><input type="text" style="width:50px;" name="hp_stock[]" value="'+v.hp_stock+'"></td>';
				   str+='<td align="center">'+v.hp_amount+'</td>';
				    str+='<td align="center"><input type="checkbox" value="1" style="float:none;" name="sku_status['+k+']" '+(v.hp_status>-1?'checked':'')+'></td>';
					});
		      
       str+='</tbody></table>';

       $('#pid_span').html(str).show();


		



		})


	
})


 <{if $smarty.get.operation=='edit'}>
 $('#pid').click();
                    <{/if}>

});
<{if $smarty.get.operation=='add' or $smarty.get.operation=='edit' or $smarty.get.operation=='batch' }>
                    var cdr = new Calendar("cdr");
                    document.write(cdr);
                    cdr.showMoreDay = true;
<{/if}>
</script>
</head>
<body>
	<div class="container">
        <div class="flow">
            <div class="itemtitle">
                <h3>全返商品</h3>
                <ul>
                    <li <{if $smarty.get.operation==''}>class="current"<{/if}>><a href="?m=<{$smarty.get.m}>&s=<{$smarty.get.s}>"><span>管理</span></a></li>
                    <li <{if $smarty.get.operation=='add'}>class="current"<{/if}>><a href="?m=<{$smarty.get.m}>&s=<{$smarty.get.s}>&operation=add"><span>添加</span></a></li>
                    <{if $smarty.get.operation=='edit'}>
                    <li class="current"><a href="#"><span>修改</span></a></li>
                    <{/if}>
                </ul>
            </div>
        </div>
        <div class="h35"></div>  
        <{if $smarty.get.operation=='add' or $smarty.get.operation=='edit' or $smarty.get.operation=='batch' }>
            <form name="form" id="form" method="post">
            <input name="id" type="hidden" id="id" value="<{$de.id}>">
            <table class="table">
                <thead>
                    <tr>
                        <th class="partition" colspan="99">全返</th>
                    </tr>
                </thead>
                <tbody>
               <!--  <tr>
                    <td width="100">全返名称</td>
                    <td>
                    <input name="hp_title" id="hp_title" type="text" class="w350" value="<{$de.hp_title}>">
                 	<div id="form-error" class="form-error"></div>
                    </td>
                </tr>
                 -->
                <tr>
                    <td>选择商品</td>
                    <td>
                    <input type="text" value="<{$de.pid}>" name="pid" id="pid" > 请输入产品id
                    <div id="form-error" class="form-error"></div>
                    </td>
                </tr>
                <tr>
        <td colspan="2" id="pid_span" style="display:none;">
        </td>
        </tr>
                <tr>
                    <td>全返图片</td>
                    <td>
                    <input name="pic" class="w350" type="text" id="pic" value="<{$de.pic}>" /><div id="form-error" class="form-error"></div>
                    [<a href="javascript:uploadfile('上传LOGO','pic',0,0,'huopin')">上传</a>] 
                    [<a href="javascript:preview('pic');">预览</a>]
                    [<a onclick="javascript:$('#pic').val('');" href="#">删除</a>] <span class="bz"></span>
                    </td>
                </tr>
               <!--  <tr>
                    <td>起止时间</td>
                    <td>
                    
                    <input onFocus="cdr.show(this);" class="ltext" type="text" name="stime" id="stime" value="<{$de.start_time|date_format}>"> 
                    <{html_select_time use_24_hours=true display_seconds=false display_minutes=false prefix=start time=$de.start_time|default:0}>:00:00
                    - 
                    <input onFocus="cdr.show(this);" class="rtext" type="text" name="etime" id="etime" value="<{$de.end_time|date_format}>">
                    <{html_select_time use_24_hours=true display_seconds=false display_minutes=false prefix=end time=$de.end_time|default:'23:59:59'}>:59:59
                    </td>
                </tr> -->
                <tr>
                    <td>最小起购数量</td>
                    <td><input type="text" name="limit_amount" value="<{if $de.limit_amount}><{$de.limit_amount}><{else}>1<{/if}>" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeyup="value=value.replace(/[^\d]/g,'')" /><div id="form-error" class="form-error"></div><p class="hint">每个会员单次购买最小件数</p></td>
				</tr>
                
                <tr>
                    <td>虚拟数量</td>
                    <td><input type="text" name="virtual_amount" value="<{if $de.virtual_amount}><{$de.virtual_amount}><{else}>0<{/if}>" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeyup="value=value.replace(/[^\d]/g,'')" /><p class="hint">虚拟购买数量，只用于前台显示，不影响成交记录</p></td>
				</tr>
                
               <!--  <tr>
                    <td>全返成功数量</td>
                    <td><input type="text" name="low_amount" value="<{if $de.low_amount}><{$de.low_amount}><{else}>1<{/if}>" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeyup="value=value.replace(/[^\d]/g,'')"/><div id="form-error" class="form-error"></div><p class="hint">全返达到此数量的时候显示全返成功</p></div></td>
				</tr>  -->
                <tr>
                    <td>状态</td>
                    <td>
                   <!--  <{if $smarty.get.operation=='edit' }><input type="radio" name="status" value="3" id="done" <{if $de.status==3}>checked="checked"<{/if}>/><label for="done">已完成</label><{/if}>
                    <{if $smarty.get.operation=='edit' }><input type="radio" name="status" value="2" id="tj" <{if $de.status==2}>checked="checked"<{/if}>/><label for="tj">备货中</label><{/if}> -->
                    <input type="radio" name="status" value="1" id="open" <{if $de.status==1}>checked="checked"<{/if}>/><label for="open">上架</label>
                    <input type="radio" name="status" value="0" id="close" <{if $de.status==0}>checked="checked"<{/if}>/><label for="close">关闭</label>
                    </td>
                </tr>
               
                <tr>
                    <td>&nbsp;</td>
                    <td>
                    <input class="submit" type="submit" value="提交">
                    <input name="act" type="hidden" id="action" value="<{if !$smarty.get.editid}>save<{else}>edit<{/if}>">
                    </td>
                </tr>
                </tbody>
            </table>
            </form>
        <{else}>
		<script type="text/javascript">
        $(function(){
            /* 全选 */
             $('.checkall').click(function(){
                var _self = this;
                $('.checkitem').each(function(){
                    if (!this.disabled)
                    {
                        $(this).attr('checked', _self.checked);
                    }
                });
                $('.checkall').attr('checked', this.checked);
            });	 
        });
        </script>
        
        <form action="" method="get">
	    <input type="hidden" name="m" value="<{$smarty.get.m}>">
	    <input type="hidden" name="s" value="<{$smarty.get.s}>">
	    <table class="select_table">
	        <tr>    
	           <td>
	                    <span>&nbsp;产品ID:</span>
           				<span>
           					<input name="productId" value="<{$smarty.get.productId}>" />
           				</span>
	                    <span>&nbsp;状态:</span>
	                    <span>
	                    	<select name="status">
	                    		<option value="">不限</option>
	                    		<option value="1" <{if $smarty.get.status=='1'}>selected<{/if}> >上架</option>
	                    		<option value="0" <{if $smarty.get.status=='0'}>selected<{/if}> >关闭</option>
                    		</select>
                   		</span>
                   		
                   		<input style="margin-left:30px;" type="submit" value="搜索" />
	           </td>
	        </tr>
	    </table>
	    </form>
        
        <form action="" method="post">
        <table class="table">
        	<thead>
                <tr>
                    <th class="partition" colspan="99"></th>
                </tr>
            </thead>
            <tbody>
                <tr class="header">
                    <th width="30"></th>
                    <th width="30">显示顺序</th>
                    <th width="30">ID</th>
                    <th width="80">图片</th>
                    <!-- <th width="100">全返名称</th> -->
                    <th width="50">商品ID</th>
                    <th width="50">全返价格</th>
                    <th width="50">零售价</th>
                    <th width="50">全返库存</th>
                    <th width="50">最低起售数</th>
                    <th width="60">实际已售数量</th>
                    <th width="50">虚拟数量</th>
                    <!-- <th width="100">火拼成功数量</th> -->
                    <!-- <th width="50">开始时间</th>
                    <th width="50">结束时间</th> -->
                    <th width="50">状态</th>
                    <th width="50">状态</th>
                    <th width="50"></th>
                </tr>
                <{foreach item=list from=$de.list}>
                <tr>
                    <td><input type="checkbox" value="<{$list.id}>" class="checkitem" name="chk[]"></td>
                    <td><input type="text" class="w50" maxlength="3" name="displayorder[<{$list.id}>]" value="<{$list.displayorder}>" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeyup="value=value.replace(/[^\d]/g,'')" /></td>
                    <td><{$list.id}></td>
                    <td width="80"><{if $list.pic}><img width="100" height="60" class="img" src="<{$list.pic}>/80" /><{else}><img class="img" width="60" src="../image/default/nopic.gif" /><{/if}></td>
                    <!-- <td width="100"><{$list.hp_title}></td> -->
                    <td><{$list.pid}></td>
                    <td><{$config.money}><{$list.price}></td>
                    <td><{$config.money}><{$list.market_price}></td>
                    <td><{$list.stocks}></td>
                    <td><{$list.limit_amount}></td>
                    <td><{$list.true_amount}></td>
                    <td><{$list.virtual_amount}></td>
                    <!-- <td><{$list.low_amount}></td> -->
                    <!-- <td><{$list.start_time}></td>
                    <td><{$list.end_time}></td> -->
                    <td><{$list.hpStatusStr}></td>
                    <td><{if $list.status==1}>开启<{elseif $list.status==2}>备货中<{elseif $list.status==3}>已完成<{else}>关闭<{/if}></td>
                    <td>
                    <a href="?m=<{$smarty.get.m}>&s=<{$smarty.get.s}>&operation=edit&editid=<{$list.id}>"><{$editimg}></a> 
                    </td>
                </tr>
                <{foreachelse}>
                <tr>
                    <td class="norecord" colspan="99"><i></i><span>暂无符合条件的数据记录</span></td>
                </tr>
                <{/foreach}>
            </tbody>
            <tfoot>
                <tr>
                	<td colspan="4">
                        <input type="checkbox" class="checkall" id="del">
                        <input type="hidden" name="act" value="op" />
                        <input type="submit" name="submit" value="<{$lang.btn_submit}>" />
                        <input type="submit" name="submit" value="备货中" />
                        <input type="submit" name="submit" value="<{$lang.btn_open}>" />
                        <input type="submit" name="submit" onclick="return confirm('您确定要设置为完成吗');" value="完成" />
                        <input type="submit" name="submit" onclick="return confirm('您确定要关闭吗');" value="<{$lang.btn_close}>" />
                        <input type="submit" name="submit" onclick="return confirm('您确定要删除吗');" value="<{$lang.del}>" />
                    </td>
                    <td colspan="99"><div class="page"><{$de.page}></div></td>
                </tr>
            </tfoot>
        </table>
        </form>
        <{/if}>
    </div>
</body>
</html>